<?php

namespace App\Services;

use AntChain\TWC\Models\BclCreatePromiseDetailInfo;
use App\Models\Order;
use App\Models\OrderCredit;
use App\Models\OrderGoods;
use App\Models\OrderLease;
class CreditCallService
{
    //新征信接口2024-03-30
    //是否查询成功
    const RESULT_SUCCESS = 1; //成功
    const RESULT_FAIL = 2; //失败
    const RESULT_ING = 3; //请求中

    //  const KEY = '3392def305d582053d368a5737821e8b';
    const KEY = '74aaf5115f824c1ab6d0bc2a1f16e8a1d'; //请求中测试3392def305d582053d368a5737821e8b
//    const privateKey='-----BEGIN PRIVATE KEY-----
//MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCdsPUhJC+/amDl
//zqkEfoH/veO8ANPs/N0Qggfo7PoKWDAho2s/Obge224ZtNIbGONOWyyPweYi8sOw
//c+wV2BUa1Fg+3ApU5qWBdRyVX/tAMjOE5V16iNsIIepPZQ4s8j1zQPxatMJTVvJq
//IchPomWWGRaOWlxwZt9IdyntcrI1JRLDyfEbdsHCrb5id3pmPvPGIG1Wz7IpVd2J
///cN3J4bFbSXDAxy5c9hWWoVfKmHKEtUnh1PCI37+BemCGgCKb9rwiHBXC6eiFCNW
//s1shzHag39g1kpveogoq3/zHgHfsDYPkNRg00PMk0Zf1bSC+RK+oE3PnJ5SsicjR
//ahHvy5PrAgMBAAECggEAPZF94/aw/deXBaLusuaB80w8wobAN+NynKNoWzVLWwab
//pEad9Q2gKcwa7MaA0juhZFKMz4QxSqvmY9qe7thzRQpref+HuSZksGr9QgU7oBD5
//tIWpPdJ5Um+LgHxAUKQ0Ae/5l6DDzq4/79hI0W7iovwgpmv5c5l2zGBaam9BzSWT
//jLrgF4Zp42R1MNQlysc36Yq/ehEu/ObX/44aKk0F0sebRt0M47S+F8q3XBOveoZp
//4ySzDYkVgVxSi1eYBmuxjgWWflK/4TaNPl9T5x0A+2WOEkbbMoPDBoGymbuEm7f3
//7+DjBqXOWXU+zkYdK3RldtLxJLzXKuALzVjFc6c+QQKBgQDJTxrU/PxHHzLu+QLg
//cr8HJd8gtPvYDzGTMA8mvLEMqxInsqf5Bi5bc3gM5wYDSfsM6mq2RtjSynoo7ckl
//6m6iniuVLFtsq0ZT1SWCPwt4LEH9ORl2lutC0nA/xh/Q9ptLwOCa/y3oaDtg3m2V
//cNSApxrsZcpmJVU5E7Tpu4t4cwKBgQDIiETaEGgi5j9gYxQ//+94Pmwwc2YwpE7m
//wrhenX9R4tXKGEbFuoncpVPkaXb46R+KrJ5BBBMOYgeH/wZD7yoo0TsTO+JP0HEQ
//Ac75mMAIVg6S1YaTwhoMwVvCA2/0uQ1V35wsdNF0J0flVhk94/keXSFEzBlkE3qb
//iFtd8e6wqQKBgDZcDxHOks0dxqIzSayUL7NdbagmVw9b4vYs9xptv519IHTp0GP1
//YFU/k/5f8Aa5VnqBXnmEHg6lsGEW/McpS+DLt1cb2EA66829c9h877rusI8ReSfF
//zxeHPdpqxLKntP26wqv4Fkx4wPgCeDLveeKXvTRytDnrAN1dze+DvkCzAoGATMb/
//tY36kQIe2cSViDtxcFRWD+bfBVijbO64sGEU0kFLIWlSD3pwNi6GhDls97gp/2o/
//3Ry2PxeBUqxttazoM2CIgcC30V85KqvGlwHI5GguhEGEmSYD20Zc31d5kfUYCfzn
//So4fc51mhYQFfhC+3MVDa5fJUOu0UcBPWxS6EqECgYB36n4SI/Fh99jbyoNSNso2
//R0dYAqMGmvBTg9IAllo07yWbXTE8aQ0/vms/N4Q8Og+xOZOneVfrTphJr/t7oMkc
//5FPghyfzeAW7CaW0tsz1CFahs8KMNnxl7Q5TtknBCD1mlgdW6SdVhGkqHsrFEYni
//mHGgDCKjPi/5NYHy1ODJPQ==
//-----END PRIVATE KEY-----';

const privateKey='-----BEGIN PRIVATE KEY-----
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDKBm6JljIJ9/X3
fWwvSUX5vleOUB2fXGdG558Bp+ldLNo27Z14ScRNKQDccn5YjobaUnauWCuZk3eM
CDXLP8Ux8OVVBhqSUwCjKsUL7Y+AVE4S4fAme19TJDxyYddrKC2N0wTvhkMEfCbp
r2Uq4SXFdK9aAUpTDsc2cs4Hb/K/+ljrjxRkwCqJE4gMiwKMGZUU9cA7ElPkcuGX
3F2XRVJowxSmxg2LVDctxk0sFb+8iyeoKJw9p+brQcztsmHgp2KePCzKSVh8/lA8
v7Tf/YXL86oWLyQjOTDUfX5qQ4L9iCoQFzbmw+Y15XN+y+MgflwgCkAw7Loyr5Vi
/7AdwniBAgMBAAECggEAE1P2M1eZRfbhI2JufT+nYDNjsQvdKafvgYsbXU8xNmba
IbMuA5obG762hGC30cUhBbYqAJgS48iGAXGvo9hgB10is7W3yRQD1Zh77Z42wnJO
XeQb07Kt9ghbeB4APBJF+XGc4UWZF87A8k6DgUy1DmUReazx7WxWhtEJAREmylL/
tSsK+bV9MlQjabc0VmGZ4P9bI0NdvWThZ4RFeY5deBxsEXJzO6ZnNXXHh02E95Zc
HzAdOKgY24npq0U9Sd1vKd2w8eTTqBrVzOcN1yEy77ErNlraICuV9B1sWsX8kiEP
X591d0TIz2TRBNxd1SvtZR3/Bw4htIoW/eW9TttpWQKBgQDnjWIDrANBbTmFuMTY
nBrXh74d26Nr3Y/Y59T5Txp8KUyXjYaSli/4pscUbScRaHY/HjX6lyYBjfg/WUv9
ajE4atFyxd9LKjIvQ+7Vi1X5vXoBitY3mD+i0X6rrz13lriWSvz7lXFM0pvSwPmn
FSinqP6gSI7OdnIY0f9ktO9YKwKBgQDfWvXwmVyt/s7p/7jZ7cr1TNHhy9r7RG6j
QFVA7kSEfPTOrlXonwGq5N02FqwzJFa8tOP/cd2JbnxgiZV8lq/v7NQyUUOw2QYx
JqxXMrlDq6n2oSXJOX3BTjp/GqHLYF/4WHZhQl5vvBDbtlVuhziHl30f0uzK4ZEK
5eV2F7VQAwKBgC8jq1aQCEGjmNhOW1S1wwkpy1yMwGJPQt+nosX2gq/QQJWB7Gmf
RbjbSyAvcIqst5X18otHhic+3dEXvs6idc7EgEtbWTAWMQ1KSS8UJLapClOSDjZX
Om1NNPqCvILCHmYKciJNtDktjyeCvdB0EEjBsMS0wM3rcyL2bYX1B9ztAoGAR1Bm
qEx/P/rUm/gPUF3RaKL/fGW3ZHTEEpHO5q1s6RRwobEeMujaAnOSgduZXbbjjtr+
1SfJAUFqqvQi66W9RRDL68jwoP2aMYVUj37dklK0MM/hHa+ijF7q5HxfXm1GFyg/
m+wx9OEKTOyZuHGqRfjDda7F9j0xL1aZ/iuxs3sCgYAcv6VWlqmgkhfRP8WBqwzP
+8lqKfTrN8izCN8tPcx33M5dYCRDtgFFmSmOFD/rmhY3f/alPB/btxQnTA9SbLzy
DifCxGrH2QSoUmSRweOZsltjuxosw4RUO55jpUPuUcwwMom/ynO6tzh48UDCvblN
IWcITxsLJFQZf61P1/6blA==
-----END PRIVATE KEY-----';

    //   const url = 'https://api.test.rentwell2021.com/api-web/api/gateway/call/credit';
  const url = 'https://api.rentwell2021.com/api-web/api/gateway/call/credit';//https://api.test.rentwell2021.com/api-web/api/gateway/call/credit

    /**
     * 获取征信结果
     */
    static public function getInvestData($order){
        $biz_content=[];
        $biz_content['applyOrderId']=$order['trade_no'];
        $biz_content['idCardNo']=$order['cert_no'];
        $biz_content['name']=$order['cert_name'];
        $biz_content['telephone']=$order['mobile'];
        $biz_content['photoFront']=config('alipay.oss.imgHost').$order['idcard_front'];
        $biz_content['photoBack']=config('alipay.oss.imgHost').$order['idcard_back'];
        $biz_content['userAuthProtocol']=config('alipay.oss.imgHost').$order['pact_url_3'];
        $biz_content['userAuthSignTime']=date('Y-m-d H:i:s',time()-60);
        $biz_content['pbcCreditAuth']=config('alipay.oss.imgHost').$order['pact_url_2'];
        $biz_content['pbcAuthSignTime']=date('Y-m-d H:i:s');
        $biz_content['productType']='v011';
        $biz_content['scc']='91330381MAC65FWH5X';
        $biz_content['companyName']='瑞安市诺明网络科技有限公司';

        $biz_content_josn=json_encode($biz_content);
// 需要加密的数据 = 业务请求合集，拼接当前时间戳
        $biz_content_res = $biz_content_josn.time();
// 私钥数据
        $privateKey =self::privateKey;
// 获取私钥资源
        $key = openssl_get_privatekey($privateKey) ;
// 通过私钥对数据进行数字签名
        openssl_sign($biz_content_res, $signature, $key, "sha256WithRSAEncryption");
        $sign = base64_encode($signature);
        $data = [
            'app_code' => self::KEY,
            'method' => 'apply_order_query',
            'timestamp' => time(),
            'version' => '1.0.0',
            'biz_content' => $biz_content_josn,
            'sign' => $sign,
        ];
        AlipayService::requestLog('获取征信结果1','',$data);

        $result = self::buerCurl(self::url,$data);

        return $result;
    }
    /**
     * 获取征信结果
     */
    static public function getInvestData2($requestId,$scoreNo){
        $biz_content=[];
        $biz_content['applyOrderId']=$scoreNo;
        $biz_content['orderId']=$requestId;

        $biz_content_josn=json_encode($biz_content);
// 需要加密的数据 = 业务请求合集，拼接当前时间戳
        $biz_content_res = $biz_content_josn.time();
// 私钥数据
        $privateKey =self::privateKey;
// 获取私钥资源
        $key = openssl_get_privatekey($privateKey) ;
// 通过私钥对数据进行数字签名
        openssl_sign($biz_content_res, $signature, $key, "sha256WithRSAEncryption");
        $sign = base64_encode($signature);
        $data = [
            'app_code' => self::KEY,
            'method' => 'apply_order_result',
            'timestamp' => time(),
            'version' => '1.0.0',
            'biz_content' => $biz_content_josn,
            'sign' => $sign,
        ];
        $result = self::buerCurl(self::url,$data);
        return $result;

    }

    /**
     * 上报征信-申请担保
     */
    static public function applyInvestData($orderId){
        $order = Order::from('sp_order_2 as o')->where('o.id',$orderId)
            ->leftjoin('sp_order_credit as c','c.order_id','o.id')
            ->leftjoin('sp_member_2 as u','o.uid','u.id')
            ->leftjoin('sp_shop_user_2 as su','o.seller_id','su.member_id')
            ->leftjoin('sp_order_goods_2 as og','o.id','og.order_id')
            ->leftjoin('sp_goods_2 as g','og.goods_id','g.id')
            ->select(
                'o.id','o.trade_no','o.begin_time','o.end_time','o.pact_url_3','o.uid','o.seller_id','o.is_insurance_choose','o.is_insurance_choose_custom',
                'o.flow_id','o.mobile','o.user_email','o.sign_num','o.address','o.rent_total','o.month_total','o.amount','o.realname','o.rent_total',
                'o.foregift','o.status','o.prov','o.city','o.area','o.sign_status','o.is_rent_choose'
                ,'c.platformLoanNo','o.create_time'
                ,'u.ant_user_id','u.mobile as user_mobile','u.id as x_user_id','u.cert_name','u.user_id','u.cert_no','u.esign_user_id'
                ,'u.idcard_front','u.idcard_back','og.pact_type','og.is_buy_out','og.goods_title','og.setmeal_title','og.lease_set','og.setmeal_price','og.setmeal_foregift',
                'og.goods_id','og.setmeal_id','og.id as order_goods_id','og.spec_id','og.lease_price','og.lease_time','og.website_price','og.start_date'
                ,'su.mechanism','su.faname','su.shopname','su.contact_tel','su.company','su.company_area','su.companyid','su.id as shop_user_id'
                ,'su.ant_user_id as mer_ant_id'
                ,'g.new_grade')
            ->first();
        $order = $order ? $order->toArray() : [];

        $OrderCredit=OrderCredit::where('order_id',$orderId)->orderBy('id','desc')->first();
        if(empty($OrderCredit['requestId'])){
            return ;
        }
        $biz_content=[];
        $biz_contenta=[];
        $biz_contenta['orderId']=$OrderCredit['requestId'];
        $biz_contenta['productName']=$order['setmeal_title'];
        $biz_contenta['productType']=$order['setmeal_title'];
        $rent_total=OrderLease::where('order_id',$order['id'])->select('id','begin_time','end_time','rent','which_period','status')->sum('rent');
        $biz_contenta['productCost']=$rent_total;
        $biz_contenta['totalRent']=$rent_total;
        $biz_contenta['rentStartDate']=strtotime('-1 hours')*1000;
        $biz_contenta['rentFinishDate']=strtotime('last day of + '.$order['month_total'].' month',time())*1000;
        $biz_contenta['periodNum']=$order['month_total'];
        $biz_contenta['periodRent']=$order['lease_price'];
        $biz_contenta['buyoutAmount']='0';
        $biz_content['order']=$biz_contenta;
        $biz_content['contract']=['leasingContract'=>''];

        $stageList=[];
        $OrderLease=OrderLease::where('order_id',$order['id'])->select('id','begin_time','end_time','rent','which_period','status')->get();

        $OrderLease=obToArray($OrderLease);
        $begin_time=$order['begin_time'];
        foreach ($OrderLease as $i=>$ra){
            if($ra['which_period']==1){
                    $ra['begin_time']=time();
                    $begin_time=time();
            }else{
                if(date("d",$begin_time)>=28){
                    $ra['begin_time']=strtotime('last day of + 1 month',$begin_time);
                    $begin_time=strtotime('last day of + 1 month',$begin_time);
                }else{
                    $ra['begin_time']=strtotime('+ 1 month',$begin_time);
                    $begin_time=strtotime('+ 1 month',$begin_time);
                }
            }

            $stageList[]=[
                'currentPeriod'=>$ra['which_period'],
                'periodAmount'=>$ra['rent'],
                'periodStatus'=>$ra['status']==1?2:1,
                'repaymentDate'=>$ra['begin_time']*1000,
                'statementDate'=>$ra['begin_time']*1000,
                'totalPeriod'=>$order['month_total'],
            ];

        }

        $biz_content['stageList']=$stageList;


        $biz_content_josn=json_encode($biz_content);
// 需要加密的数据 = 业务请求合集，拼接当前时间戳
        $biz_content_res = $biz_content_josn.time();
// 私钥数据
        $privateKey =self::privateKey;
// 获取私钥资源
        $key = openssl_get_privatekey($privateKey) ;
// 通过私钥对数据进行数字签名
        openssl_sign($biz_content_res, $signature, $key, "sha256WithRSAEncryption");
        $sign = base64_encode($signature);
        $data = [
            'app_code' => self::KEY,
            'method' => 'leasing_contract_apply',
            'timestamp' => time(),
            'version' => '1.0.0',
            'biz_content' => $biz_content_josn,
            'sign' => $sign,
        ];
        $result = self::buerCurl(self::url,$data);
        if($result['code']=='ZHZ00000'){
            OrderGoods::where('order_id',$orderId)->update(['up_credit'=>1]);
        }
        return $result;
    }
    /**
     *
     * 上报征信-担保放款
     */
    static public function remitInvestData($orderId){

        $OrderCredit=OrderCredit::where('order_id',$orderId)->orderBy('id','desc')->first();
        $biz_content=[];
        $biz_content['orderId']=$OrderCredit['requestId'];

        $biz_content_josn=json_encode($biz_content);
// 需要加密的数据 = 业务请求合集，拼接当前时间戳
        $biz_content_res = $biz_content_josn.time();
// 私钥数据
        $privateKey =self::privateKey;
// 获取私钥资源
        $key = openssl_get_privatekey($privateKey) ;
// 通过私钥对数据进行数字签名
        openssl_sign($biz_content_res, $signature, $key, "sha256WithRSAEncryption");
        $sign = base64_encode($signature);
        $data = [
            'app_code' => self::KEY,
            'method' => 'leasing_contract_fetch',
            'timestamp' => time(),
            'version' => '1.0.0',
            'biz_content' => $biz_content_josn,
            'sign' => $sign,
        ];
        $result = self::buerCurl(self::url,$data);
        return $result;


    }
    /**
     * 上报征信-还款
     */
    static public function repayInvestData($order_id,$lease_id){
        $order=OrderLease::where('order_id',$order_id)->where('id',$lease_id)->select('id','trade_no','which_period','rent','begin_time','end_time','status')->first();
        $OrderCredit=OrderCredit::where('order_id',$order_id)->orderBy('id','desc')->first();
        if(empty($OrderCredit['requestId'])){
            return ;
        }
        $biz_content=[];
        $biz_content['orderId']=$OrderCredit['requestId'];
        $biz_content['period']=$order['which_period'];
        $biz_content['amount']=$order['rent'];
        $biz_content['repayType']=$order['status']==1?1:2;
        $biz_content_josn=json_encode($biz_content);
// 需要加密的数据 = 业务请求合集，拼接当前时间戳
        $biz_content_res = $biz_content_josn.time();
// 私钥数据
        $privateKey =self::privateKey;
// 获取私钥资源
        $key = openssl_get_privatekey($privateKey) ;
// 通过私钥对数据进行数字签名
        openssl_sign($biz_content_res, $signature, $key, "sha256WithRSAEncryption");
        $sign = base64_encode($signature);
        $data = [
            'app_code' =>self::KEY,
            'method' => 'leasing_repay',
            'timestamp' => time(),
            'version' => '1.0.0',
            'biz_content' => $biz_content_josn,
            'sign' => $sign,
        ];
        $result = self::buerCurl(self::url,$data);
        return $result;

    }
    /**
     * 上报征信-逾期还款
     */
    static public function overdueRepayInvestData($input){


        // $key = "C2811D4EE95E4835A327F11E21CA3382";   //密钥-测试环境
        $key = "FA4F1CB125684F3285B836D0613006FC";   //密钥-正式环境

        // $url = "https://server.junxinhengyi.cn:16633/api/guarantee/v2/overdueRepay"; //测试
        $url = "https://serice.junxinhengyi.cn:4433/api/guarantee/v2/overdueRepay"; //线上

        $user = array(
            'platformLoanNo'=>$input['platformLoanNo'], //申请担保接口返回的担保平台单号
            'period'=>$input['which_period'], //租期
            'amount'=>$input['rent'],//还款金额
            'repayDate'=>date('Y-m-d H:i:s'), //还款日期
        );

        $jsonData = json_encode($user);
        $signString = self::encrypt($jsonData,$key);

        $sign = strtoupper(md5('secretKey='.$key.'&data='.$signString.'&timestamp='.date('Y-m-d H:i:s')));
        $data = array(
            'data' => $signString, //签名域
        );
        // dd($data);

        $paramstring = json_encode($data);
        // dd($paramstring);
        $content = self::buerCurl1($url,$sign,$paramstring);
        // dd($content);
        $result = json_decode($content,true);  //返回结果
        // dd($result);
        return $result;

    }
    /**
     * 上报征信-结清
     */
    static public function settleInvestData($input){


        // $key = "C2811D4EE95E4835A327F11E21CA3382";   //密钥-测试环境
        $key = "FA4F1CB125684F3285B836D0613006FC";   //密钥-正式环境

        // $url = "https://server.junxinhengyi.cn:16633/api/guarantee/v2/settle"; //测试
        $url = "https://serice.junxinhengyi.cn:4433/api/guarantee/v2/settle"; //线上

        $user = array(
            'platformLoanNo'=>$input['platformLoanNo'], //申请担保接口返回的担保平台单号
            'initCredName'=>'瑞安市诺明网络科技有限公司',//初始债权人名称（资金方全称），催收总金额大于0时必填
            'initCredOrgNum'=>'91330381MAC65FWH5X',//初始债权人名称（资金方全称），催收总金额大于0时必填
            'compensatoryMoney'=>$input['compensatoryMoney'], //催收总金额=在保期限内的（代偿总本金额-代偿还款总本金额）+未还利息(可为未还正常利息+未缴罚息等),未还金额
            'origDbtCate'=>"9",//原债务种类(催收总金额大于0时必填)
            "initRpySts"=>0,//债务转移时的还款状态（若有代偿，此数据为必须）对于资产处置业务，填写该笔债务的初始债权人转让债权时，债务人的还款状态；对于垫款业务，填写发生垫款时债务人的履约状态。
            'fivecate'=>2,//五级分类
        );

        $jsonData = json_encode($user);
        $signString = self::encrypt($jsonData,$key);

        $sign = strtoupper(md5('secretKey='.$key.'&data='.$signString.'&timestamp='.date('Y-m-d H:i:s')));
        $data = array(
            'data' => $signString, //签名域
        );
        // dd($data);

        $paramstring = json_encode($data);
        // dd($paramstring);
        $content = self::buerCurl1($url,$sign,$paramstring);
        // dd($content);
        $result = json_decode($content,true);  //返回结果
        // dd($result);
        return $result;

    }
    /**
     * 上报征信-追偿
     */
    static public function dunRepayInvestData($input){

        // $key = "C2811D4EE95E4835A327F11E21CA3382";   //密钥-测试环境
        $key = "FA4F1CB125684F3285B836D0613006FC";   //密钥-正式环境

        // $url = "https://server.junxinhengyi.cn:16633/api/guarantee/v2/dunRepay"; //测试
        $url = "https://serice.junxinhengyi.cn:4433/api/guarantee/v2/dunRepay"; //线上

        $user = array(
            'platformLoanNo'=>$input['platformLoanNo'], //申请担保接口返回的担保平台单号
            'surplusAmount'=>$input['surplusAmount'], //当前追偿后剩余金额
            'amount'=>$input['amount'],//追偿本金额
            'dunDate'=>$input['dunDate'], //追偿日期
            "fivecate"=>"2"
        );

        $jsonData = json_encode($user);
        $signString = self::encrypt($jsonData,$key);

        $sign = strtoupper(md5('secretKey='.$key.'&data='.$signString.'&timestamp='.date('Y-m-d H:i:s')));
        $data = array(
            'data' => $signString, //签名域
        );
        // dd($data);

        $paramstring = json_encode($data);
        // dd($paramstring);
        $content = self::buerCurl1($url,$sign,$paramstring);
        // dd($content);
        $result = json_decode($content,true);  //返回结果
        // dd($result);
        return $result;

    }

    /**
     * 上报征信-追偿结清
     */
    static public function dunSettleInvestData($input){


        // $key = "C2811D4EE95E4835A327F11E21CA3382";   //密钥-测试环境
        $key = "FA4F1CB125684F3285B836D0613006FC";   //密钥-正式环境

        // $url = "https://server.junxinhengyi.cn:16633/api/guarantee/v2/dunSettle"; //测试
        $url = "https://serice.junxinhengyi.cn:4433/api/guarantee/v2/dunSettle"; //线上

        $user = array(
            'platformLoanNo'=>$input['platformLoanNo'], //申请担保接口返回的担保平台单号
            'settleDate'=>$input['settleDate'], //追偿日期
            "fivecate"=>"2"
        );

        $jsonData = json_encode($user);
        $signString = self::encrypt($jsonData,$key);

        $sign = strtoupper(md5('secretKey='.$key.'&data='.$signString.'&timestamp='.date('Y-m-d H:i:s')));
        $data = array(
            'data' => $signString, //签名域
        );
        // dd($data);

        $paramstring = json_encode($data);
        // dd($paramstring);
        $content = self::buerCurl1($url,$sign,$paramstring);
        // dd($content);
        $result = json_decode($content,true);  //返回结果
        // dd($result);
        return $result;

    }

    /**
     * 上报征信-合同重新发送请求
     */
    static public function agreementInvestData($input){


        // $key = "C2811D4EE95E4835A327F11E21CA3382";   //密钥-测试环境
        $key = "FA4F1CB125684F3285B836D0613006FC";   //密钥-正式环境

        // $url = "https://server.junxinhengyi.cn:16633/api/guarantee/v2/agreement"; //测试
        $url = "https://serice.junxinhengyi.cn:4433/api/guarantee/v2/agreement"; //线上

        $user = array(
            'platformLoanNo'=>$input['platformLoanNo'], //申请担保接口返回的担保平台单号
            'agreementType'=>"2", //合同类型：2委托担保合同；1保函
        );

        $jsonData = json_encode($user);
        $signString = self::encrypt($jsonData,$key);

        $sign = strtoupper(md5('secretKey='.$key.'&data='.$signString.'&timestamp='.date('Y-m-d H:i:s')));
        $data = array(
            'data' => $signString, //签名域
        );
        // dd($data);

        $paramstring = json_encode($data);
        // dd($paramstring);
        $content = self::buerCurl1($url,$sign,$paramstring);
        // dd($content);
        $result = json_decode($content,true);  //返回结果
        // dd($result);
        return $result;

    }

    /**
     * 请求接口返回内容 -查询
     * @param  string $url [请求的URL地址]
     * @param  string $params [请求的参数]
     * @param  int $ipost [是否采用POST形式]
     * @return  string
     */
    static private function buerCurl($url,$data=null){
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_HTTPHEADER,['Accept: application/json','User-Agent: */*','Content-Type: application/json']); //设置header头
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // 从证书中检查SSL加密算法是否存在
            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data,true));
            $output = curl_exec ($ch);
            curl_close ($ch);
            return json_decode($output,true);
    }






}
